ABC286 C - Rotate and Palindrome
提出
WA
code: python
import math
n, a, b = list(map(int, input().split()))
s = input()
# max = n//2 * b
# ずらすメリットがない
ans = 0
if a >= b:
for i in range(n//2):
ans += b
else:
for i in range(n//2):
ans += b
# 左端に同じのが固まっていたら
same = 0
for i in range(n//2 - 1):
same += 1
# 1 -> 1, 2 -> 1, 3 -> 2, 4 -> 2, 5 -> 3
ans -= math.ceil(same/2) * b
ans += math.ceil(same/2) * a
print(ans)
解答
code: python
n, a, b = map(int, input().split())
s = list(input())
s += s
# print(s)
ans = pow(10, 60)
for i in range(n):
# i回ずらす
tmp = a * i
for j in range(n // 2):
# if i == 1:
# print((i+j), (i -(j+1) + n))
# 1 5
# 2 4
tmp += b
ans = min(ans, tmp)
print(ans)
メモ
提出
code: python
n, a, b = map(int, input().split())
s = list(input())
# print(s)
# b * n - max s
# まずどれを置き換えるか